package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.domain.vo.ContentCategoryVO;
import com.dongdongshop.domain.vo.ContentVO;
import com.dongdongshop.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("category")
@RefreshScope   //监听配置文件
@CrossOrigin   //跨域问题
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    //查询全部
    @GetMapping("categoryList")
    public Result categoryList(){
        List<ContentCategoryVO> list = categoryService.contentList();
        return Result.OK().setData(list);
    }

    //增加
    @PostMapping("add")
    public Result addCategory(@RequestBody ContentCategoryVO vo){
        return categoryService.addCategory(vo);
    }

    //根据ID查询/回显
    @GetMapping("selectById")
    public Result selectById(@RequestParam Long id){
        ContentCategoryVO vo = categoryService.selectById(id);
        return Result.OK().setData(vo);
    }

    //修改
    @PutMapping("update")
    public Result updateCategory(@RequestBody ContentCategoryVO vo){
        return categoryService.updateCategory(vo);
    }

    //批量删除
    @DeleteMapping("deleteCategory")
    public Result deleteCategory(@RequestBody List<Long> ids){
        return categoryService.deleteCategory(ids);
    }

}
